package com.cloudservice.ccs.biz.impl;

import com.cloudservice.ccs.biz.IWorkOrderReplyBiz;
import com.cloudservice.ccs.entity.WorkOrderReply;
import com.cloudservice.ccs.exception.WorkOrderReplyException;
import com.cloudservice.ccs.mapper.WorkOrderMapper;
import com.cloudservice.ccs.mapper.WorkOrderReplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class WorkOrderReplyImpl implements IWorkOrderReplyBiz {

    @Autowired
    private WorkOrderReplyMapper workOrderReplyMapper;

    @Override
    public void save(WorkOrderReply workOrderReply) {
        int res = workOrderReplyMapper.save(workOrderReply);
        if (res == 0) {
            throw new WorkOrderReplyException("Create WorkOrder failed");
        }
    }

    @Override
    public void update(Integer id, WorkOrderReply workOrderReply) {
        int res = workOrderReplyMapper.update(id, workOrderReply);
        if (res == 0) {
            throw new WorkOrderReplyException("Update WorkOrder failed");
        }
    }

    @Override
    public void partialUpdate(Integer id, Map<String, Object> fields) {
        int res = workOrderReplyMapper.partialUpdate(id, fields);
        if (res == 0) {
            throw new WorkOrderReplyException("Partial update WorkOrder failed");
        }
    }

    @Override
    public void delete(Integer id) {
        int res = workOrderReplyMapper.delete(id);
        if (res == 0) {
            throw new WorkOrderReplyException("Delete WorkOrder failed");
        }
    }

    @Override
    public WorkOrderReply getOne(Integer id) {
        WorkOrderReply workOrderReply = workOrderReplyMapper.getOne(id);
        if (workOrderReply == null) {
            throw new WorkOrderReplyException("Requested WorkOrderReply does not exist");
        }
        return workOrderReply;
    }

    @Override
    public List<WorkOrderReply> getAll() {
        return workOrderReplyMapper.getAll();
    }
}
